﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using Sharebert.LoggingLibrary.API;

namespace Sharebert.LoggingLibrary
{
    public class Logbert : ILogger
    {
        public Logbert()
        {
            this.LogDebug = true;
            this.LogInfo = true;
            this.LogWarn = true;
            this.LogError = true;
        }

        public void Debug(string message)
        {
            if (this.LogDebug)
            {
                Log(LogType.Debug, message);
            }
        }

        public void Debug(string message, Exception ex)
        {
            if (this.LogDebug)
            {
                Log(LogType.Debug, message, ex);
            }
        }

        public void Info(string message)
        {
            if (this.LogInfo)
            {
                Log(LogType.Info, message);
            }
        }

        public void Info(string message, Exception ex)
        {
            if (this.LogInfo)
            {
                Log(LogType.Info, message, ex);
            }
        }

        public void Warn(string message)
        {
            if (this.LogWarn)
            {
                Log(LogType.Warn, message);
            }
        }

        public void Warn(string message, Exception ex)
        {
            if (this.LogWarn)
            {
                Log(LogType.Warn, message, ex);
            }
        }

        public void Error(string message)
        {
            if (this.LogError)
            {
                Log(LogType.Error, message);
            }
        }

        public void Error(string message, Exception ex)
        {
            if (this.LogError)
            {
                Log(LogType.Error, message, ex);
            }
        }


        private void Log(LogType type, string message)
        {
            Log(type, message, null);
        }

        private void Log(LogType type, string message, Exception ex)
        {
            if (this.MessageLogged != null)
            {
                this.MessageLogged.Invoke(this, new LogEventArgs(type, message, ex));
            }
        }


        public bool LogDebug { get; set; }

        public bool LogInfo { get; set; }

        public bool LogWarn { get; set; }

        public bool LogError { get; set; }


        public event EventHandler<LogEventArgs> MessageLogged;

    }
}
